package com.lh.createData.service.Impl;

import com.lh.createData.dao.ProjAvgMapper;
import com.lh.createData.model.InPutParam.ProjAvgInParam;
import com.lh.createData.model.InPutParam.ProjAvgReportInParam;
import com.lh.createData.model.ProjAvgReportModel;
import com.lh.createData.myenum.TotalTypeEnum;
import com.lh.createData.service.ProjAvgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：梁昊，后端工程师：梁昊
 * @create 2021-07-20 19:07
 * @function
 * @editLog
 */
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Service
public class ProjAvgServiceImpl implements ProjAvgService {
    @Autowired
    ProjAvgMapper projAvgMapper;

    /**
     * 根据ProjCode与众多条件，删除加权平均值记录
     *
     * @param projAvgInParam com.lh.createData.model.InPutParam.ProjAvgInParam
     * @return 影响条数
     */
    @Override
    public int deleteProjAvgByMult(ProjAvgInParam projAvgInParam, TotalTypeEnum totalTypeEnum) {
        int resultValue = 0;
        switch (totalTypeEnum) {
            case YEAR:
                resultValue = projAvgMapper.deleteProjAvgByYear(projAvgInParam);
                break;
            case HALFYEAR:
                resultValue = projAvgMapper.deleteProjAvgByHalfYear(projAvgInParam);
                break;
            case SEASON:
                resultValue = projAvgMapper.deleteProjAvgBySeason(projAvgInParam);
                break;
            case MONTH:
                resultValue = projAvgMapper.deleteProjAvgByMonth(projAvgInParam);
                break;
            case DAY:
                resultValue = projAvgMapper.deleteProjAvgByDay(projAvgInParam);
                break;
        }
        return resultValue;
    }

    /**
     * 增加项目加权平均值
     *
     * @param projAvgInParam com.lh.createData.model.InPutParam.ProjAvgInParam
     * @return 影响条数
     */
    @Override
    public int insertProjAvg(ProjAvgInParam projAvgInParam, TotalTypeEnum totalTypeEnum) {
        deleteProjAvgByMult(projAvgInParam, totalTypeEnum);
        return projAvgMapper.insertProjAvg(projAvgInParam);
    }
    /**
     * 按月、季度、半年、年统计项目加权平均值
     *
     * @param projAvgReportInParam com.lh.createData.model.InPutParam.ProjAvgReportInParam
     * @return 影响条数
     */
    @Override
    public List<ProjAvgReportModel> selectProjAvgByProjectAndTime(ProjAvgReportInParam projAvgReportInParam) {
        return projAvgMapper.selectProjAvgByProjectAndTime(projAvgReportInParam);
    }

}